Demo 地址
https://github.com/iKangtai/ShecareSDKDemo-iOS.git
类定义
核心服务类:ShecareService
1 | /** |
YCEnvironment 定义如下:1
2
3
4
5
6
7/// SDK 使用的服务器环境
public enum YCEnvironment: Int {
/// 正式服务器
case release = 0
/// 测试服务器
case tester = 1
}
温度类:YCTemperatureModel
1 | /** |
属性列表:1
2
3
4
5
6/// 是否已删除
public var deleted: Bool = false
/// 测温时间
public var measureTime: NSDate?
/// 温度数据
public var temperature: NSString = ""
经期类:YCPeriodModel
1 | /** |
属性列表:1
2
3
4/// 记录日期
public var date: NSDate?
/// 经期信息:1 表示经期开始,2 表示经期结束,0 表示删除经期或无经期信息。经期开始和结束应该成对出现
public var period: Int = 0
用户基础信息类:YCUserInfoModel
1 | /** |
属性列表:1
2
3
4
5
6
7
8
9
10/// 周期长度,默认值 28
public var cycleLength: Float = 28.0
/// 经期长度,默认值 5
public var mensLength: Float = 5.0
/// 出生年月,默认值
public var birth: String = "1995年1月"
/// 身高,默认值 160
public var height: Int = 160
/// 体重,默认值45
public var weight: Float=45.2
用户生理信息类:YCPhyModel
1 | /** |
属性列表:1
2
3
4
5
6
7
8
9
10
11
12
13/// 白带,默认值0
public var mucus: Int = 0
/// LH,默认值 0
public var lh: Int = 0
/// 同房,默认值 0
public var hadSex: Int = 0
/// B超,默认值
public var bUltra: Int = 160
/// 激素六项,默认值null
public var hormoneSix: String="以Json的形式组织相关的激素六项记录"
{"e2":300,"fsh":14,"lh":13,"p":20,"t":0.30,"prl":0.14}
/// 症状,默认0
public var symptom: Int = 0
用户基础信息类:YCHealthInfoModel
1 | /** |
属性列表:1
2
3/// 健康信息,默认值 null
public var health: String = "以Json的形式上传"
如:{"pcos":1,"endometriosis":0,"tubalOperation":0,"abortion":0,"ivf":0,"lpd":0}
接口说明
SDK 初始化
AppDelegate 里需要使用 ShecareService 设置第三方 appID、appSecret 和用户 ID,如下:1
2
3
4
5
6
7
8
9/// 设置 appID
/// - parameter identifier: 由 SaaS 服务端提供
public func setApplicationIdentifier(_ identifier: String)
/// 设置 appSecret
/// - parameter identifier: 由 SaaS 服务端提供
public func setApplicationSecret(_ identifier: String)
/// 设置 UserID
/// - parameter identifier: App 用户标识符,由 App 提供
public func setUserIdentifier(_ identifier: String)
示例如下:1
2
3ShecareService.shared().setApplicationIdentifier(appID)
ShecareService.shared().setApplicationSecret(appSecret)
ShecareService.shared().setUserIdentifier(userID)
数据初始化
SDK 首次加载时,需要把用户的历史数据(包括经期、体温等)一次性传入,用于算法计算。后续有新数据时,只需要传人新数据即可。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16/**
判断 SDK 是否需要数据初始化
- returns:
返回 true 时,App 需要调用 initData 方法进行数据初始化
*/
func needInitData() -> Bool
/**
数据初始化。
- parameters:
- temperatures: 用户的体温数据,可为空
- periods:用户的经期数据,可为空
- userInfo:用户的基础生理信息,不可为空
- completion:完成回调
*/
public func initData(temperatures: [YCTemperatureModel]?, periods: [YCPeriodModel]?, userInfo: YCUserInfoModel, completion: @escaping (NSError?) -> Void)
示例如下:1
2
3
4
5
6
7
8
9if ShecareService.shared().needInitData() {
ShecareService.shared().initData(temperatures: temperatures, periods: periods, userInfo: userInfo, completion: { (result) in
if result {
// Shecare SDK 数据初始化成功
} else {
// Shecare SDK 数据初始化失败
}
})
}
绑定设备
绑定页面 UI 由 SDK 提供,绑定过程中与设备的交互也由 SDK 负责。App 只需要打开 SDK 绑定页即可。
绑定页面类定义:YCBindViewController
属性:1
2
3
4/**
代理
*/
weak public var delegate: YCBindViewControllerDelegate?
实例化和设置代理,示例如下:1
2
3
4let vc = YCBindViewController()
vc.delegate = self
let navC = UINavigationController(rootViewController: vc)
self.show(navC, sender: nil)
代理方法:1
2
3
4
5
6
7
8/**
返回绑定结果的代理方法
- parameters:
- bindViewController: 当前的绑定页面控制器
- macAddress: 绑定的设备 MAC 地址
- error: 错误信息。当为空时,表示没有错误
*/
func bindViewController(_ bindViewController: YCBindViewController, didBind macAddress: String, error: NSError?)
实现代理方法,示例如下:1
2
3
4
5
6
7
8
9
10
11
12
13extension ViewController: YCBindViewControllerDelegate {
func bindViewController(_ bindViewController: YCBindViewController, didBind macAddress: String) {
showAlert(title: "绑定成功", message: macAddress, confirmHandler: { (_) in
bindViewController.dismiss(animated: true, completion: nil)
}, cancelHandler: nil)
}
func bindViewController(_ bindViewController: YCBindViewController, didFailedToBind macAddress: String, errorMessage: String) {
showAlert(title: "绑定失败", message: macAddress + "\n" + errorMessage, confirmHandler: { (_) in
bindViewController.dismiss(animated: true, completion: nil)
}, cancelHandler: nil)
}
}
解绑设备
1 | /** |
示例如下:1
ShecareService.shared().unBind(macAddress: "C8:FD:19:02:95:7E")
增量上传 温度、经期和用户基础生理信息
1 | /** |
返回基础体温曲线页面 URL
1 | /** |
示例如下:1
2
3
4let webVC = YCWebViewController()
webVC.urlString = ShecareService.shared().temperatureCharts()
webVC.title = "体温曲线"
self.navigationController?.pushViewController(webVC, animated: true)
返回 智能分析 结果。App 端根据需要对分析结果进行处理。
1 | /** |
示例如下:1
2
3
4
5
6
7ShecareService.shared().analysis({ (error, result) in
if let error = error {
print(error)
} else {
print(result ?? "analysis result is nil.")
}
})
智能分析结果说明:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111{
"code": 0,
"message": null,
"data": {
"listAll": [
{
"list": [
{
"state": "normal",
"msg": "测温时间不规律,大部分在10点和11之间。",
"guanjian": null,
"url": null
},
{
"state": "bigwave",
"msg": "到目前体温测量一切正常,加油哦!",
"guanjian": null,
"url": null
},
{
"state": "pregnant",
"msg": "根据基础体温,确定排卵日为2018年3月1日。",
"guanjian": null,
"url": null
},
{
"state": "noyellow",
"msg": "黄体升温幅度较低,速度较慢,疑似黄体功能不足。",
"guanjian": null,
"url": null
}
],
"nowdate": "当前周期:2018年2月18日--今天"
},
{
"list": [
{
"state": "normal",
"msg": "测温时间不规律,大部分在10点和11之间。",
"guanjian": null,
"url": null
},
{
"state": "bigwave",
"msg": "到目前体温测量一切正常,加油哦!",
"guanjian": null,
"url": null
},
{
"state": "pregnant",
"msg": "根据基础体温,确定排卵日为2018年1月29日。",
"guanjian": null,
"url": null
},
{
"state": "noyellow",
"msg": "黄体升温幅度较低,速度较慢,疑似黄体功能不足。",
"guanjian": null,
"url": null
},
{
"state": "noyellow",
"msg": "本周期黄体期长度为18。长度过长,正常黄体其长度为10-16天。",
"guanjian": null,
"url": null
}
],
"nowdate": "历史周期:2018年1月1日--2018年2月17日"
},
{
"list": [
{
"state": "normal",
"msg": "本周期无有效的基础体温。",
"guanjian": null,
"url": null
}
],
"nowdate": "历史周期:2017年11月17日--2017年12月31日"
},
{
"list": [
{
"state": "normal",
"msg": "本周期无有效的基础体温。",
"guanjian": null,
"url": null
}
],
"nowdate": "历史周期:2017年10月1日--2017年11月16日"
},
{
"list": [
{
"state": "normal",
"msg": "周期长度最长48天,最短45天,平均周期长度47,周期长度稳定!",
"guanjian": null,
"url": null
},
{
"state": "normal",
"msg": "经期长度最长6天,最短3天,平均经期长度4,经期长度稳定。",
"guanjian": null,
"url": null
}
],
"nowdate": "整体周期分析:"
}
]
}
}
备注:当 code 非0时,说明内部分析出错,此时会在 message 中返回错误信息; listall 中的数据主要用到了:nowdate 和 message,nowdate 表示该段数据所处的周期, message 表示对这段周期分析的结果。
蓝牙
类定义:BLEThermometer
1 | /** |
属性列表:
1 | /// 当前连接的外部设备 |
YCBLEConnectType,蓝牙连接类型,定义如下:
1 | /// 蓝牙连接类型 |
YCBLEState,蓝牙状态,定义如下:
1 | /// 蓝牙状态 |
BLEFirmwareImageType,设备镜像版本,用于 OAD 空中升级,定义如下:
1 | /// 用户硬件镜像版本 |
BLENotifyType,设备可接收的指令,定义如下:
1 | /// 指令类型 |
方法列表
扫描并连接设备
1 | /** |
停止扫描
1 | /** |
返回蓝牙状态
1 | /** |
断开当前连接的设备
1 | /** |
同步设备时间
1 | /** |
发送特定指令
1 | /** |
蓝牙代理方法列表
1 | /// 设备蓝牙状态改变的回调 |
1 | /// 获取设备镜像版本的回调,详见 BLEFirmwareImageType 定义 |
1 | /// 设备连接成功的回调 |
1 | /// 设备连接失败的回调 |
1 | /// 设备断开连接的回调 |
1 | /// 获取温度的回调 |
1 | /// 设置设备温度单位的回调 |
1 | /// 获取设备版本号的回调 |
1 | /// 同步设备时间的回调 |
1 | /// 获取设备电量的回调 |